package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.ConsultTitleEntity;
import com.runen.infinitemovement.tool.CommonUtil;

/**
 * Create by LiaoDuanHong
 * Create on
 */
public class ConsultTitleAdapter extends BaseQuickAdapter<ConsultTitleEntity, BaseViewHolder> {
    private Context context;
    private boolean isLinearLayoutManager;
    private float height;

    public ConsultTitleAdapter(Context context, boolean isLinearLayoutManager, float height) {
        super(R.layout.item_consult_title);
        this.context = context;
        this.isLinearLayoutManager = isLinearLayoutManager;
        this.height = height;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ConsultTitleEntity entity) {
        TextView tvContent = baseViewHolder.findView(R.id.tv_content);
        LinearLayout ll_content = baseViewHolder.findView(R.id.ll_content);
        ImageView iv_flag = baseViewHolder.findView(R.id.iv_flag);

        if (isLinearLayoutManager) {
            if (baseViewHolder.getAdapterPosition() == 0) {
                ll_content.setPadding(CommonUtil.dp2px(context, 15), 0, 0, 0);
            }
        } else {
            ll_content.setPadding(0, 0, 0, 0);
        }
        tvContent.setText(entity.typeName);
        if (entity.isSelect) {
            tvContent.setTextColor(context.getResources().getColor(R.color.color_FFED3F37));
            tvContent.setBackgroundResource(R.drawable.bg_white_dp13);
            iv_flag.setVisibility(View.VISIBLE);
        } else {
            tvContent.setTextColor(Color.WHITE);
            tvContent.setBackground(null);
            iv_flag.setVisibility(View.INVISIBLE);
        }
        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        tvContent.measure(w, h);
        iv_flag.measure(w, h);
        //机型适配
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) iv_flag.getLayoutParams();
        layoutParams.topMargin = (int) (height - CommonUtil.getStatusBarHeight(context) -
                CommonUtil.dp2px(context, 33) - tvContent.getMeasuredHeight()
                - iv_flag.getMeasuredHeight());
        iv_flag.setLayoutParams(layoutParams);
    }
}
